﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using dllLink;

namespace ASPGerant
{
    public partial class gerant_2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Nécessaire pour pouvoir utiliser SQL Server CE avec un site ASP
            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);

        }

        public String computeCov()
        {
            ulong n;
            String affichage = "";
            try
            {
                String temp = Request.QueryString["N"];
                if (temp != null && !temp.Equals(""))
                {
                    n = Convert.ToUInt64(temp);
                }
                else
                {
                    n = 100;
                }
            }
            catch (Exception)
            {
                n = 100;
            }
            
            Interface adaptateur = new Interface();
            Double[,] Result = adaptateur.computePrice(n);
            double r = Result[0,0];
            affichage += "<center>Calcul réalisé avec N = " + n + "<br /><table border =\"1\"><tr bgcolor=\"#C0C0C0\" height=\"35\" align=\"center\"><td><b>Actif</b></td><td><b>Delta</b></td><td><b>Monnaie</b></td><td>Intervalle de confiance</td><td> à 99%</td></tr>";
            for (int i = 1; i < 13; i++)
                affichage += "<tr height=\"35\"><td>&nbsp;&nbsp;" + Interface.Naming[i] + "&nbsp;&nbsp;</td><td>&nbsp;&nbsp;" + Result[i, 0] + "&nbsp;&nbsp;</td><td align=\"center\">" + Interface.Devise[i] + "</td><td>&nbsp;&nbsp;" + Result[i, 1] + "&nbsp;&nbsp;</td><td>&nbsp;&nbsp;" + Result[i, 2] + "&nbsp;&nbsp;</td></tr>";
            affichage += "</table> <br /> Pricing = " + r +" Intervalle de confiance : "+Result[0,1]+" # " + Result[0,2]+"<br />";
            DateTime now = DateTime.Now;
            DateTime begin = new DateTime(2002,6,19);

            TimeSpan ecart = now.Subtract(begin);

            double days = ecart.Days;
            double p = Math.Pow(r/100,365.0/days)-1;
            p = Math.Round(p * 10000)/100;
            affichage += "Rentabilité annualisée : " + p +" %</center>";

            return affichage;

        }
    }
}
